function KeyboardHandler() {
	this.onKeyPress = function() { };
	this._handlers = new Array();
	Event.observe(document, "keypress", this.keyboard_onKeyPress.bindAsEventListener(this));
}

KeyboardHandler.Keys = new Object();
KeyboardHandler.Keys.NONE	= 0;
KeyboardHandler.Keys.CONTROL 	= 1;
KeyboardHandler.Keys.SHIFT 	= 2;
KeyboardHandler.Keys.ALT 	= 4;

KeyboardHandler.prototype.reset = function() {
	this._handlers = new Array();
}

KeyboardHandler.prototype.addHandler = function(key, modifiers, callback) {
	var handler = {key:key.toLowerCase(), modifiers:modifiers, callback:callback};
	this._handlers.push(handler);
}

KeyboardHandler.prototype.keyboard_onKeyPress = function(event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	var key = String.fromCharCode(keyCode).toLowerCase();
	var currModifiers = 0;
	if(event.ctrlKey) currModifiers += KeyboardHandler.Keys.CONTROL;
	if(event.shiftKey) currModifiers += KeyboardHandler.Keys.SHIFT;
	if(event.altKey) currModifiers += KeyboardHandler.Keys.ALT;
	
	for(var i=0; i<this._handlers.length; i++) {
		var handler = this._handlers[i];
		if(handler.key == key && currModifiers == handler.modifiers) {
			handler.callback();
		}
	}
}

